<?php
namespace app\teacherComment\controller;
use app\common\Base;
use think\Db;

class TeacherCommentQuery extends Base {
	
	public function index() {
		return $this->fetch();
	}

	public function pageQuery() {
		$where = [];
		$termId = input("termId");
		$grade = input("grade");
		$subjectId = input("subjectId");
		$commentType = input("类别");
		$level = input("获奖级别");
		$rank = input("获奖等第");
		$teacherName = input("teacherName");
		$startDate = input("startDate");
		$endDate = input("endDate");
		$page = input("page");
		$rows = input("rows");
		if($termId) $where["学期ID"] = $termId;
		if($grade) {
			$array = explode("_", $grade);
			$where["年级号"] = array("eq", $array[0]);
			$where["学籍类型"] = array("eq", $array[1]);
		}
		if($subjectId) $where["任教学科ID"] = $subjectId;
		if($commentType) $where["类别"] = $commentType;
		if($level) $where["获奖级别"] = $level;
		if($rank) $where["获奖等第"] = $rank;
		if($teacherName) $where["姓名"] = array("like",$teacherName);
		$result = Db::table('教师考评')->alias('a')
				  ->join('学期名称 b','a.学期ID=b.ID','LEFT')
				  ->join('教师信息 c','a.教师ID=c.ID','LEFT')
				  ->join('学科名称 d','c.任教学科ID=d.ID','LEFT')
				  ->field("a.ID,a.类别,a.项目名称,a.项目内容,a.教师ID,a.获奖级别,a.获奖等第,a.获奖时间,a.立项时间,a.结题时间,a.颁发单位,a.加分,a.备注,a.学期ID,b.学期名称,c.姓名,c.年级号,d.学科名称")
				  ->where($where)
				  ->order("学期ID desc,ID desc")
				  ->page($page, $rows)
		          ->select();
		$count = Db::table('教师考评')->alias('a')
				  ->join('教师信息 c','a.教师ID=c.ID','LEFT')
				  ->where($where)
				  ->count();
		$grid['rows'] = selectResult($result);
        $grid['total'] = $count;
		return $grid;
	}

}
